package com.hyf.popupdemo.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.Toast;

import com.hyf.popupdemo.DataSource;
import com.hyf.popupdemo.R;
import com.hyf.popupdemo.base.BaseActivity;
import com.hyf.popupdemo.support.PopWindowMenuHelper;
import com.hyf.popupdemo.support.PopupWindowMenu;
import com.hyf.popupdemo.support.PopwindowMenuRelativeLayout;

import java.util.List;

public class TestAnyweherShowPopActivity extends BaseActivity {

    private PopwindowMenuRelativeLayout contentView;

    private List<PopupWindowMenu> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_anyweher_show_pop);
        setDisplayHomeAsUpEnabled();
        initView();
        initData();
        initListener();
    }

    private void initListener() {
        contentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new PopWindowMenuHelper.MiddleBuilder(getActivity(), list, contentView)
                        .setOnPopItemClickListener(menuItemClickListener)
                        .setShowTriangle(false)
                        .setIsBlur(false)
                        .show();
            }
        });
    }

    private void initData() {
        list = DataSource.getMenuList();
    }

    private void initView() {
        contentView = (PopwindowMenuRelativeLayout) findViewById(R.id.anywhere_pop_rl_content);
    }


    private PopWindowMenuHelper.OnItemClickListener menuItemClickListener = new PopWindowMenuHelper.OnItemClickListener() {
        @Override
        public void onClickPopwindowMenuItem(View view, PopupWindow window, int position) {
            Toast.makeText(getContext(), list.get(position).getTitle(), Toast.LENGTH_SHORT).show();
            window.dismiss();
        }
    };
}
